![Get Email Alerts when Stage of EC2 Instance Changes by using SNS and Eventbridge](https://devio2023-media.developers.io/wp-content/uploads/2022/08/amazon-ec2.png)
Get Email Alerts when Stage of EC2 Instance Changes by using SNS and Eventbridge
Introduction
Hemanth of Alliance Department here. In this blog, I tried to get email alerts when stage of EC2 instance changes by making use of SNS and Event bridge.
EC2
It is a service offered by Amazon Web Services for cloud computing (AWS). By offering scalable cloud computing power through EC2, users can rent virtual computers on which to execute their own apps. When managing and scaling applications in the cloud, EC2 offers a flexible, affordable, and simple solution.
SNS
A fully managed messaging service for both application to application and application to person. A2A pub/sub functionality provides topics for high-throughput, push-based, many-to-many messaging between distributed systems, microservices, and event-driven serverless applications. The A2P functionality enables you to send messages to users at scale via SMS, mobile push, and email.
AWS EventBridge
AWS services, Software-as-a-Service (SaaS), and bespoke applications can connect with each other using events thanks to Amazon EventBridge, a serverless event bus. The service has seen a number of upgrades since its introduction, including the addition of the event replay and schema registry. The scheduler is the most recent addition.
Demo
Go to SNS and click on create topic
Next click on standard, give a name and click on create topic
Now create subscription and click on create subscription
Select the earlier created topic in ARN, protocol click on Email, endpoint give your email id and click on create subscription
Current status show's pending as confirmation, check your mail box for confirmation
Checking back in SNS, Status has changed to confirmed
Now moving to EventBridge and creating a rule
Giving a name, keeping others as default and click next
Making the following changes in the Event pattern and click next
click on SNS topic in target, choose the above created SNS topic and in aditional setting setting choose input transformer to make changes in the email structure.
click on input transformer next click on input path and making the following changes and end has $region
Scroll down, template will be the email body fill in as below and click on confirm
keep clicking on next and finally click on create rule
Rule is successfully created
Now moving to EC2 and clicking on stop instance
Intance has successfully stopped and now check in the email
Conclusion
I hope with this you have an understanding of how to make use of SNS and eventbridge to send email notifications to user when the EC2 instance changes it's state.